/*
This file is part of luacalc
(C) 2006 Richard Simes
You may distribute it under the terms of the GNU General Public License
*/


#ifndef LUACALCUI_H
#define LUACALCUI_H



#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#else
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#endif

#include <wx/grid.h>
#include <wx/clipbrd.h>

#ifdef __cplusplus
extern "C" {
#endif


#include "lua.h"

#include "lauxlib.h"
#include "lualib.h"

#ifdef __cplusplus
}
#endif

class LuaCalcFrame;

/**

*/
class LuaCalc: public wxApp {
public:
//	LuaCalc();
	bool OnInit();
private:
	LuaCalcFrame* frame;
	
};


class LuaCalcFrame: public wxFrame {
	public:
	
	LuaCalcFrame(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE);
	
	void Save();
	void Open();
	void Sort();
	void Quit(bool close=true);
	
	void CopyData();
	void PasteData();
	
	void Undo();
	void Redo();
	
	
	bool IsDirty();
	void Record();
	void move(int, int);
		void Replay();
	
	
	/* Event Handlers */    
	void OnQuit(wxCommandEvent& event);
	void OnExit(wxCloseEvent& event);
	void OnAbout(wxCommandEvent& event);
	void OnOpen(wxCommandEvent& event);
	void OnSave(wxCommandEvent& event);
	void OnSort(wxCommandEvent& event);
	void OnUndo(wxCommandEvent& event);
	void OnRedo(wxCommandEvent& event);
	void OnSelect(wxGridEvent& event);
	void OnKeyDown(wxKeyEvent& event);
	void OnHelp(wxCommandEvent& event);
	void OnSaveMacro(wxCommandEvent& event);
	void OnLoadMacro(wxCommandEvent& event);
	void OnPlot(wxCommandEvent& event);
	
	
	wxGrid* grid;
	
	
	DECLARE_EVENT_TABLE()
	
private:
	void SetProperties();
	void GetFunctions();
	void DoLayout();
	/* the name of the open spreadsheet file. */
	const char* filename;
	bool macroRunning;
	int row, col;
	wxMenu* functions;

	lua_State* L;
	

};

/* event IDs */
enum
{
	ID_Quit=1,
	ID_About,
	ID_Open,
	ID_Save,
	ID_Sort,
	ID_Undo,
	ID_Redo,
	ID_Help,
	ID_SaveMacro,
	ID_LoadMacro,
	ID_Plot,
	ID_Functions
};

/* event bindings */
BEGIN_EVENT_TABLE(LuaCalcFrame, wxFrame)
	EVT_MENU     (ID_Quit, LuaCalcFrame::OnQuit)
	EVT_MENU     (ID_Open, LuaCalcFrame::OnOpen)
	EVT_MENU     (ID_Save, LuaCalcFrame::OnSave)
	EVT_MENU     (ID_About, LuaCalcFrame::OnAbout)
	EVT_MENU     (ID_Sort, LuaCalcFrame::OnSort)
	EVT_MENU     (ID_Undo, LuaCalcFrame::OnUndo)
	EVT_MENU     (ID_Redo, LuaCalcFrame::OnRedo)
	EVT_MENU     (ID_Help, LuaCalcFrame::OnHelp)
	EVT_MENU     (ID_SaveMacro, LuaCalcFrame::OnSaveMacro)
	EVT_MENU     (ID_LoadMacro, LuaCalcFrame::OnLoadMacro)
	EVT_MENU     (ID_Plot, LuaCalcFrame::OnPlot)
	EVT_KEY_DOWN (LuaCalcFrame::OnKeyDown)
	EVT_CLOSE    (LuaCalcFrame::OnExit)
	EVT_GRID_SELECT_CELL(LuaCalcFrame::OnSelect)
END_EVENT_TABLE()



#endif // LUACALCUI_H
